package com.hoopchina.util.xml;

import java.io.StringWriter;
import java.util.List;

import org.xmlpull.v1.XmlPullParserFactory;
import org.xmlpull.v1.XmlSerializer;

import android.util.Xml;

import com.hoopchina.meta.NewsItem;


public class NewsList2String {
	 public static String produceXml(List<NewsItem> newsItems){  
         
	        StringWriter stringWriter = new StringWriter();  
	      
	        try {  
	            // 获取XmlSerializer对象   
	            XmlPullParserFactory factory = XmlPullParserFactory.newInstance();  
	            XmlSerializer xmlSerializer = factory.newSerializer();  
	         // 设置输出流对象   
	             xmlSerializer.setOutput(stringWriter);  
	             xmlSerializer.startDocument("utf-8", true);  
	             xmlSerializer.startTag(null, "allnews");  
	             for(NewsItem items:newsItems){  
 
	            	xmlSerializer.startTag("", "news");
	     			xmlSerializer.startTag("", "title");
	     			xmlSerializer.text(items.getTitle());
	     			xmlSerializer.endTag("", "title");

	     			xmlSerializer.startTag("", "url");
	     			xmlSerializer.text(items.getUrl());
	     			xmlSerializer.endTag("", "url");

	     			xmlSerializer.startTag("", "abs");
	     			xmlSerializer.text(items.getAbs());
	     			xmlSerializer.endTag("", "abs");

	     			xmlSerializer.startTag("", "author");
	     			xmlSerializer.text(items.getAuthor());
	     			xmlSerializer.endTag("", "author");
	     			
	     			xmlSerializer.startTag("", "time");
	     			xmlSerializer.text(items.getTime());
	     			xmlSerializer.endTag("", "time");
	     			
	     			xmlSerializer.startTag("", "publictime");
	     			xmlSerializer.text(items.getmPublicTime());
	     			xmlSerializer.endTag("", "publictime");
	     			
	     			xmlSerializer.startTag("", "imgUrl");
	     			xmlSerializer.text(items.getImgUrl());
	     			xmlSerializer.endTag("", "imgUrl");
	     			xmlSerializer.endTag("", "news");  
	            }  
	            xmlSerializer.endTag(null, "allnews");  
	            xmlSerializer.endDocument();  
	        } catch (Exception e) {  
	            e.printStackTrace();  
	         }  
	        return stringWriter.toString();  
	  
	     }  

}
